import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

const state = {
	userInfo: {},
	cityInfo: {},
	sid: {},
	token: "",
	addressInfo: {},
	msgAudio: "",
	msgVideo: "",
	defaultAddress:{},
	selfCity: "",
	navbar: [],
	editAddress: {},
	Access_token: "",
	ckcode: "",
	UserRole: "",
	ServerName: {},
	shopData: [],
	OrderInfo: {},
	confirmMaster: "",
	areadyRate: "",
}

const mutations = {
	getUserInfo: (state, msg) => {
		state.userInfo = msg
	},
	getCityInfo: (state, msg) => {
		state.cityInfo = msg
	},
	getSid: (state, msg) => {
		state.sid = msg
	},
	getUserToken: (state, token) => {
		state.token = token
	},
	getAddRess: ( state, address) => {
		state.addressInfo = address
	},
	getMsgAudio: (state, msg) => {
		state.msgAudio = msg
	},
	getMsgVideo: (state, msg) => {
		state.msgVideo = msg
	},
	getDefaultAddress: (state, add) => {
		state.defaultAddress = add
	},
	getSelfCity: (state, city) => {
		state.selfCity = city
	},
	getNavbar: (state, navbar) => {
		state.navbar = navbar
	},
	getEditAddress: ( state, add) => {
		state.editAddress = add
	},
	getAccess_token: (state, token) => {
		state.Access_token = token
	},
	getCkCode: (state, img) => {
		state.ckcode = img
	},
	getUserRole: (state, role) => {
		state.UserRole = role
	},
	getServerName: (state, name) => {
		state.ServerName = name
	},
	getShopData: (state, data) => {
		state.shopData = data
	},
	getOrderInfo: ( state, info) => {
		state.OrderInfo = info 
	},
	// 确认师傅后 得到状态 订单页面接收到状态跳转到待支付页面
	getConfirmMaster: (state, bloo) => {
		state.confirmMaster = bloo
	},
	// 支付完成后 给予状态  调用函数 查看是否已经评价
	getAreadyRate: ( state, rate ) => {
		state.areadyRate = rate
	},
	
}

const actions = {
	emitUserInfo: ({ commit }, msg) => {
		commit("getUserInfo", msg)
	},
	emitSid: ( { commit }, msg) => {
		commit("getSid", msg)
	},
	emitToken: ( { commit }, token) => {
		commit("getUserToken", token)
	},
	emitAddRess: ( { commit }, info) => {
		commit("getAddRess", info)
	},
	emitMsgAudio: ( { commit }, info) => {
		commit("getMsgAudio", info)
	},
	emitDefaultAddress: ( { commit }, info) => {
		commit("getDefaultAddress", info)
	},
	emitSelfCity: ({ commit }, city) => {
		commit("getSelfCity", city)
	},
	emitNavbar: ( { commit }, navbar) => {
		commit("getNavbar", navbar)
	},
	emitCityInfo: ( {commit}, msg) => {
		commit("getCityInfo", msg)
	},
	emitAccess_token: ({ commit }, token) => {
		commit("getAccess_token", token)
	},
	emitCkCode: ( { commit }, img) => {
		commit("getCkCode", img)
	},
	emitOrderInfo: ( { commit }, info) => {
		commit("getOrderInfo", info)
	},
	emitConfirmMaster: ( { commit }, bloo) => {
		commit("getConfirmMater", bloo)
	},
}

const store = new Vuex.Store({
	state,
	mutations,
	actions
})

export default store